import requests
class add_uesr:

    cookies = {
        'JSESSIONID': 'F9F683DA9519948D3BEA2991DFA7D966',
        'tempTokenKey': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjM0LCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzIxNjEwNDI1LCJleHAiOjE3MjE2MzkyMjV9.QZOXOTFv3r135D-qNGWgaOmEvuy3c5T7pbzdgiSuDaViBhxPFUzrtm2LLkyxY0WeJzs2I2j17oLpmJjE9WLF9A',
        'userInfoKey': '{^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:34^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}',
        'pwdState': 'true',
        'inspurRoleKey': 'ROLE_AREA',
        'windowId': '0B7CA12E92004E0ABCA9EB88F0A792E4',
        'James_cookie_sYQDUGqqzHtheme': 'custom',
        'webfinal.session.errorCount': '0',
        'wyhtml': '/bsp/_190d8236592236c_1721613116818',
        'wyhijack': '/sxgl/static/js/hinclude.min.js_1721611216660',
    }

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        # 'Accept-Encoding': 'gzip, deflate',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'X-Requested-With': 'XMLHttpRequest',
        'Origin': 'http://59.215.206.188',
        'Connection': 'keep-alive',
        'Referer': 'http://59.215.206.188/zhslzy/accept/system/window/index',
        # 'Cookie': 'JSESSIONID=F9F683DA9519948D3BEA2991DFA7D966; tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6bnVsbCwicm9sZSI6IlJPTEVfQVJFQSxST0xFX1dJTkRPVyIsImlzSW5pdGlhbFBhc3N3b3JkIjoiMCIsInJlZ2lvbk5hbWUiOiLotLXlt57nnIEiLCJpbmR1c3RyeSI6bnVsbCwiYXBwQ29kZSI6ImRnb3YtcG9ydGFsIiwib3JnYW5OYW1lIjoi5LqR5LiK6LS15beeIiwicmVnaW9uQ29kZSI6IjUyMDAwMCIsImluZHVzdHJ5TGlzdCI6bnVsbCwib3JnYW5Db2RlIjoiNTIwMDAyIiwiZXhwaXJhdGlvblRpbWUiOjM0LCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzIxNjEwNDI1LCJleHAiOjE3MjE2MzkyMjV9.QZOXOTFv3r135D-qNGWgaOmEvuy3c5T7pbzdgiSuDaViBhxPFUzrtm2LLkyxY0WeJzs2I2j17oLpmJjE9WLF9A; userInfoKey={^%^22role^%^22:^%^22ROLE_AREA^%^2CROLE_WINDOW^%^22^%^2C^%^22isInitialPassword^%^22:^%^220^%^22^%^2C^%^22regionName^%^22:^%^22^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^E7^%^9C^%^81^%^22^%^2C^%^22appCode^%^22:^%^22dgov-portal^%^22^%^2C^%^22organName^%^22:^%^22^%^E4^%^BA^%^91^%^E4^%^B8^%^8A^%^E8^%^B4^%^B5^%^E5^%^B7^%^9E^%^22^%^2C^%^22regionCode^%^22:^%^22520000^%^22^%^2C^%^22phone^%^22:^%^22384d53fa06a4844cfd54260b048c33e9^%^22^%^2C^%^22organCode^%^22:^%^22520002^%^22^%^2C^%^22expirationTime^%^22:34^%^2C^%^22name^%^22:^%^221342b48e6f8f39ea7ba36accc05b61a8^%^22^%^2C^%^22id^%^22:^%^229E1059C9335D4C7CB8DC7400D03AECFB^%^22^%^2C^%^22email^%^22:^%^22aa67c9bf293c42e9144476195b550c0f^%^22^%^2C^%^22username^%^22:^%^2247d57692a252657367001b6a2ff35333^%^22^%^2C^%^22status^%^22:^%^221^%^22^%^2C^%^22isWeakPwd^%^22:^%^220^%^22}; pwdState=true; inspurRoleKey=ROLE_AREA; windowId=0B7CA12E92004E0ABCA9EB88F0A792E4; James_cookie_sYQDUGqqzHtheme=custom; webfinal.session.errorCount=0; wyhtml=/bsp/_190d8236592236c_1721613116818; wyhijack=/sxgl/static/js/hinclude.min.js_1721611216660',
        'Priority': 'u=0',
    }
    def query(self):
        data = {
            '_search': 'true',
            'nd': '1721614735132',
            'rows': '240',
            'page': '1',
            'sidx': 'sort',
            'sord': 'asc',
            'windowShowCode': 'xzbsy',
            'windowName': '',
            'userName': '',
            'itemCode': '',
            'itemName': '',
            'hallName': '',
            'regionName': '',
            'orgName': '',
            'orgCode': '',
        }

        response = requests.post('http://59.215.206.188/zhslzy/accept/system/window/query', cookies=self.cookies,
                                 headers=self.headers, data=data).json()

        list=[]
        for item in response['rows']:
            print(item)

            WINDOW_ID=item['cell']['WINDOW_ID']
            list.append(WINDOW_ID)
        #print(response)
        print(list)
        return list

    def add(self):
        params = {
            'method': 'saveUsers',
        }
        list=self.query()
        print(list)
        for item in list:
            data = {"windowId":"{}".format(item),
                    "addUsers":[{"ID":"20150204101334018896","NAME":"陈彪"},
                                {"ID":"52000020160523114509039294","NAME":"李桥"},
                                {"ID":"EAB9A744B72B431798024380A6EDCCA6","NAME":"李聪"},
                                ],
                    "delUsers":"[]"}

            response = requests.post(
                'http://59.215.206.188/zhslzy/accept/system/window',
                params=params,
                cookies=self.cookies,
                headers=self.headers,
                json=data,
            ).json()
            print(response)
add_uesr().add()
